package repositories;

import java.util.Collection;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import domain.Vecino;

@Repository
public interface VecinoRepository extends JpaRepository<Vecino, Integer> {

	@Query("select v from Vecino v where v.userAccount.id = ?1")
	Vecino findByUserAccountId(int userAccountId);

	@Query("select v from Vecino v where v.userAccount.username = ?1")
	Vecino findByUsername(String username);

	@Query("select c.vecinos from ComunidadDeVecinos c where c.id = ?1")
	Collection<Vecino> findByCommunity(int communityId);

	@Query("select v from Vecino v where v.moroso = true")
	Collection<Vecino> findByMorosos();

	@Query("select c.vecinos from ComunidadDeVecinos c where not  c.id = ?1")
	Collection<Vecino> findByNotCommunity(int communityId);

	@Query("select v from Vecino v where v.moroso = false")
	Collection<Vecino> findByNoMorosos();

	@Query("select r.asistentes from Reunion r where r.id = ?1")
	Collection<Vecino> findAsistentesByReunion(int reunionId);

	@Query("select c.vecinos from ComunidadDeVecinos c join c.vecinos v where  c.id=?1 and v.moroso = true")
	Collection<Vecino> findByMorososByComunidad(int comunidadId);
}
